package com.model;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class Deck {
	private List<Card> deck = new LinkedList<Card>();

	public Deck () {
		newDeck();
	}
	
	public void addOnTop(Card card) {
		deck.add(0,card);
	}
	
	public Card takeOffTop() {
		Card c = deck.get(0);
		deck.remove(0);
		return c;
	}
	
	public int size() {
		return deck.size();
	}
	
	public void emptyDeck() {
		deck.clear();
	}
	
	public Card getAtIndex(int index) {
		return deck.get(index);
	}
	
	public Card removeFromIndex(int index) {
		Card c = deck.get(index);
		deck.remove(index);
		return c;
	}
	
	public int search(Suit suit, Rank rank) {
		int i = 0;
		for(Card card : deck)
			if(card.suit() == suit && card.rank() == rank)
				return i;
			else
				i++;
		
		return -1;
	}
	public void newDeck() {
		emptyDeck();
		for(Suit suit : Suit.values()) {
			for(Rank rank : Rank.values()) {
				deck.add(new Card(suit,rank));
			}
		}
		shuffle();
	}

	public void shuffle() {
		Collections.shuffle(deck);
	}
	
	public List<Card> getDeckofCards() {
		return deck;
	}

}
